﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Framework.Library.Base.Base;
using Framework.Library.Base.Extensions;
using Framework.Library.Data.DAL;
using Framework.Library.Data.DAO;
using System.Linq;
using Framework.Library.Core.Utils.GlobalHelper;
using Framework.Library.Core.Config;
using Framework.Library.Data.DAL.JObject;

namespace Framework.Portal.Layouts.Client.Modules.Menu
{
    public partial class Banmoi : BaseControl
    {
        private static List<PortalMenu> lst = new List<PortalMenu>();

        public Banmoi()
        {
        }

        public Banmoi(JSection section)
        {
            if(!string.IsNullOrEmpty(section.parameter))
            {
                string[] arrParams = section.parameter.Split('&');
                if (arrParams.Length > 0)
                    menuId = Convert.ToInt32(arrParams[0].Split('=')[1]);
                if (arrParams.Length > 1)
                    catId = Convert.ToInt32(arrParams[1].Split('=')[1]);
            }
            MENUNAME = section.title;
        }
        public string MENUNAME = string.Empty;
        protected static int catId = 0;
        protected static int menuId = 0;
        protected static int curMenu = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int totalRecord;
                List<PortalUser> lstUser = ManagerFactory.PortalUserManager.GetList((int)UserType.govn, 0, 8, out totalRecord);
                if (lstUser != null)
                {
                    rptContent.DataSource = lstUser;
                    rptContent.DataBind();
                }
            }
        }

        protected void rptContent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var info = (PortalUser)e.Item.DataItem;
                var imgAvatar = (Image)e.Item.FindControl("imgAvatar");
                var hplAuthor = (HyperLink)e.Item.FindControl("hplAuthor");

                imgAvatar.ImageUrl = info.AVATAR;
                if (info.TYPE == (int)UserType.govn)
                    info.USERID = info.DESTUSERID;
                hplAuthor.NavigateUrl = "http://my.go.vn/?id=" + info.USERID;
                hplAuthor.Text = info.USERNAME;
            }
        }
    }
}